package com.opensource.component.query.method;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
import com.opensource.component.query.script.ExtendMybatisCommand;
import com.opensource.component.query.script.MybatisCommand;

/**
 * @author ZonLen since on 2021/12/18 下午5:14
 */
public class ClickhouseExtendInsertOne extends AbstractExtendMethod {

  @Override
  public String sqlFormat(TableInfo tableInfo) {
    String columnScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlColumnMaybeIf(null),
        LEFT_BRACKET, RIGHT_BRACKET, null, COMMA);
    String valuesScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlPropertyMaybeIf(null),
        LEFT_BRACKET, RIGHT_BRACKET, null, COMMA);
    return String
        .format(sqlCommandType().getSql(), tableInfo.getTableName(), columnScript, valuesScript);
  }


  @Override
  public MybatisCommand sqlCommandType() {
    return ExtendMybatisCommand.CLICKHOUSE_INSERT_EXTEND;
  }
}